#ifndef __CTABCONTROLUI_H__
#define __CTABCONTROLUI__
#pragma once
#include<vector>
#include <algorithm>

namespace DuiLib
{
	const int ADDTABBTN = 0;

	class CTabControlButton
	{
	public:
		int id;
		RECT rect;
		int state;
	};

	class CTabPage
	{
	public:
		CStdString caption;
		CTabControlButton* closebtn;
		int movingX;
		int orderNum;
		RECT rect;
		int state;
	};

	class UILIB_API CTabControlUI : public CControlUI
	{
	private:
		CTabControlButton* AddTabPageButton;
		int animation;
		bool timerstart;
		std::vector<CTabControlButton*> Buttons;
		bool Contains(RECT rect,POINT pt);
		DWORD dw_TabPageHotFontColor;
		DWORD dw_TabPageNormalFontColor;
		DWORD dw_TabPageSelectedFontColor;
		bool ismousedown;
		int lastClickTabX;
		int lastClickX;
		CStdString m_DefaultTabPageText;
		CStdString m_sBkAddTabPageHotImage;
		CStdString m_sBkAddTabPageNormalImage;
		CStdString m_sBkAddTabPagePushedImage;
		CStdString m_sBkCloseTabPageHotImage;
		CStdString m_sBkCloseTagPageNormalImage;
		CStdString m_sBkCloseTabPagePushedImage;
		CStdString m_sBkTabPageHotImage;
		CStdString m_sBkTabPageNormalImage;
		CStdString m_sBkTabPageSelectedImage;
		std::vector<CTabPage*> TabPages;
		void ClearButtonState(EVENTTYPE_UI eventType);
		void ClearTabPageState(EVENTTYPE_UI eventType);
		RECT CopyRect(RECT copyRect);
		RECT DisplayRect();
		int GetHeaderWidth();
		void PaintTabPage(HDC hDC,CTabPage* tabPage);
		void PaintTabPages(HDC hDC);
		void ResetLayout();
	public:
		void SetMoving();
		CTabControlUI();
		void AddTabPage(CTabPage* tabPage);
		void DoEvent(TEventUI& event);
		void DoMouseDown();
		void DoMouseLeave();
		void DoMouseMove();
		void DoMouseUp();
		void DoPaint(HDC hDC, const RECT& rcPaint);
		void DoTimer();
		CStdString GetBkAddTabPageHotImage();
		CStdString GetBkAddTabPageNormalImage();
		CStdString GetBkAddTabPagePushedImage();
		CStdString GetBkCloseTabPageHotImage();
		CStdString GetBkCloseTabPageNormalImage();
		CStdString GetBkCloseTabPagePushedImage();
		CStdString GetBkTabPageHotImage();
		CStdString GetBkTabPageNormalImage();
		CStdString GetBkTabPageSelectedImage();
		CStdString GetDefaultTabPageText();
		DWORD GetTabPageHotFontColor();
		DWORD GetTabPageNormalFontColor();
		DWORD GetTabPageSelectedFontColor();
		CTabPage* GetSelectedTabPage();
		std::vector<CTabPage*> GetTabPages();
		void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
		void SetBkAddTabPageHotImage(CStdString sBkAddTabPageHotImage);
		void SetBkAddTabPageNormalImage(CStdString sBkAddTabPageNormalImage);
		void SetBkAddTabPagePushedImage(CStdString sBkAddTabPagePushedImage);
		void SetBkTabPageHotImage(CStdString sCloseTabPageHotImage);
		void SetBkTabPageNormalImage(CStdString sBkTabPageNormalImage);
		void SetBkTabPageSelectedImage(CStdString sBkTabPageSelectedImage);
		void SetBkCloseTabPageHotImage(CStdString sCloseTabPageHotImage);
		void SetBkCloseTabPageNormalImage(CStdString sCloseTagPageNormalImage);
		void SetBkCloseTabPagePushedImage(CStdString sCloseTabPagePushedImage);
		void SetDefaultTabPageText(CStdString defaultTabPageText);
		void SetSelectedTabPage(CTabPage* tabPage);
		void SetTabPageHotFontColor(DWORD TabPageHotFontColor);
		void SetTabPageNormalFontColor(DWORD TabPageNormalFontColor);
		void SetTabPageSelectedFontColor(DWORD TabPageSelectedFontColor);
		void SetPos(RECT rc);
	};
}
#endif